package com.itsenpupulai.bdtest.utils;

import com.itsenpupulai.bdtest.app.MyApp;
import com.itsenpupulai.bdtest.bean.User;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * Created by Administrator on 2017/5/9.
 */

public class DBUtil {

    public static void insertUser(User user){
        MyApp.getDaoSession().getUserDao().insert(user);
    }

    public static void deleteUser(long id){
        MyApp.getDaoSession().getUserDao().deleteByKey(id);
    }

    public static void updateByUser(User user){
        MyApp.getDaoSession().getUserDao().update(user);
    }

    public static List<User> queryAll(){
        return MyApp.getDaoSession().getUserDao().loadAll();
    }

    public static String dateFormat(long date){
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return dateFormat.format(date);
    }

    public static void deleteAll(){
        MyApp.getDaoSession().getUserDao().deleteAll();
    }

}
